Swift Pocket Reference by Anthony Gray

Swift Pocket Reference by Anthony Gray

Author:Anthony Gray
Language: eng
Format: epub, pdf
Publisher: O'Reilly Media, Inc.
Published: 2014-12-15T00:00:00+00:00


To access an overridden subscript, use super[indexValue].

Overriding properties

You can’t actually override a property in a superclass with your own property (it wouldn’t make sense to duplicate the storage space), but you can override a property in order to provide your own custom getter and setter for the superclass instance, or add a property observer so that you can be informed when the property value changes.

Earlier in this section, we introduced the Rect class for storing arbitrary rectangles. The example that follows creates a derived class, Square(), that overrides the width and height properties with new getters and setters which ensure that the height and width always match, and therefore that instances of the Square class are always in fact square:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.